package com.kerrykidz.system.util.quartz;

import java.util.Calendar;
import java.util.Date;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.quartz.QuartzJobBean;

import com.rdp.util.config.SpringUtil;

public class OrderQuartz extends QuartzJobBean {

	private static final String UPDATE_SQL = "update pos_order set order_status = '5',modi_time=now() where order_status='1' and modi_time<?";

	@Override
	protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
		Date today = this.getTodayDate();
		JdbcTemplate jdbcTemplate = SpringUtil.getBeanByType(JdbcTemplate.class);
		jdbcTemplate.update(UPDATE_SQL, today);
	}

	private Date getTodayDate() {
		Calendar c = Calendar.getInstance();
		c.set(Calendar.HOUR_OF_DAY, 0);
		c.set(Calendar.MINUTE, 0);
		c.set(Calendar.SECOND, 0);
		return c.getTime();
	}

}
